// src/store/modules/app.ts 
import { createSlice } from '@reduxjs/toolkit'
interface IAppState {
    collapsed: boolean
}
// const initialState: IAppState = {
//   collapsed: false
// }
const initialState = {
    collapsed: localStorage.getItem('collapsed') === 'true'
} as IAppState

export const appSlice = createSlice({
    name: 'app',
    initialState,
    reducers: {
        changeCollapsed(state) {
            // 每次操作的时候保存状态到本地存储
            localStorage.setItem('collapsed', String(!state.collapsed))
            state.collapsed = !state.collapsed
        }
    }
})

// 导出方法是为了我们后面导入快速使用 
export const { changeCollapsed } = appSlice.actions
export default appSlice.reducer